/**
	Pulsar engine. Core.
	Date and time managment - windows extension

	Copyright (C) 2013-2014 Dmitry Dolgov

	This program is free software; you can redistribute it and/or modify it under the terms of the
	GNU General Public License as published by the Free Software Foundation; either version 2 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
	without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	See the GNU General Public License for more details.
*/

#include <pulsar/pulsar.h>
#include <pulsar/src/pulsar_intr.h>

/**
*/
bool pl::convertWin2Fs(const FILETIME& fileTimeWin, pl::DateTime& fileTimeFs)
{
	SYSTEMTIME sysTime;

	if (!FileTimeToSystemTime(&fileTimeWin, &sysTime))
	{
		return false;
	}

	fileTimeFs.msecond = (pl_uint16)sysTime.wMilliseconds;
	fileTimeFs.second = (pl_uint8)sysTime.wSecond;
	fileTimeFs.minute = (pl_uint8)sysTime.wMinute;
	fileTimeFs.hour = (pl_uint8)sysTime.wHour;
	fileTimeFs.day = (pl_uint8)sysTime.wDay;
	fileTimeFs.month = (pl_uint8)sysTime.wMonth;
	fileTimeFs.year = (pl_uint16)sysTime.wYear;
	return true;
}

/**
	TODO - move to datetime extension
*/
bool pl::convertFs2Win(const pl::DateTime& fileTimeFs, FILETIME& fileTimeWin)
{
	SYSTEMTIME sysTime;

	sysTime.wMilliseconds = fileTimeFs.msecond;
	sysTime.wSecond = fileTimeFs.second;
	sysTime.wMinute = fileTimeFs.minute;
	sysTime.wHour = fileTimeFs.hour;
	sysTime.wDay = fileTimeFs.day;
	sysTime.wMonth = fileTimeFs.month;
	sysTime.wYear = fileTimeFs.year;

	return SystemTimeToFileTime(&sysTime, &fileTimeWin) ? true : false;
}

//
// End of file 'pulsar_datetime_win.cpp'
//
